package com.thwj.project.app.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.thwj.project.amap.dto.AppLocationDTO;
import com.thwj.project.biz.domain.Association;
import com.thwj.project.biz.service.IAssociationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class AppAssociationService {

    @Autowired
    IAssociationService associationService;

    public List<Association> getAssociationList(AppLocationDTO appLocationDTO) {
        // 读取当前以生效的社区信息
        List<Association> associationList = associationService.list(new QueryWrapper<Association>().eq("valid", true));
        // 如果是当前城市匹配放在最前面
        for (int i = 0; i < associationList.size(); i++) {
            if (associationList.get(i).getCodeCity().compareTo(appLocationDTO.getCodeCity()) == 0){
                associationList.add(0, associationList.remove(i));
            }
        }
        return associationList;
    }
}
